package wowrl;

import java.awt.Dimension;
import java.awt.Toolkit;

import javax.swing.JFrame;
import javax.swing.JPanel;

import wowrl.data.WOWRL_Data;
import wowrl.engine.WOWRL_Engine;
import wowrl.gui.WOWRL_GUI;
import wowrl.gui.CharacterCreation.CreateAttributes;


public class MainWOWRL {
	
	static JFrame window;
	
	static WOWRL_Data gameState;
	static WOWRL_Engine engine;
	static WOWRL_GUI gui;
	static CreateAttributes createAttributes;
	
    public static void main(String[] args) {       
		// Create the game objects
		gameState = new WOWRL_Data();
		engine = new WOWRL_Engine(gameState);
        gui = new WOWRL_GUI(engine);        
        createAttributes = new CreateAttributes(engine);     
        
		// Show the Create Attributes screen
        launchPanel(createAttributes);		
		
        // Wait until Create Attributes is done
		while (!createAttributes.done) {}
		
		// Show the core GUI
		gui.Start();
		launchPanel(gui);
		
    }
    
    private static void launchPanel(JPanel panel)
    {
    	// Create the window, with title
    	// Creating a new window each time we launch ensures there aren't any clashes
		window = new JFrame("WOW RL - The Azeroth RogueLike");
		
		// Add the JPanel
		window.setContentPane(panel);
		
		// Resize the window to match the contents 
		window.pack();
		
		// Makes the window open in the middle of the screen
		Dimension screensize = Toolkit.getDefaultToolkit().getScreenSize();
		window.setLocation((screensize.width - window.getWidth()) / 2,
				(screensize.height - window.getHeight()) / 2);

		// Set the program to terminate if this window is closed
		window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		// Disable resizing the window
		window.setResizable(false);

		// Make the window visible
		window.setVisible(true);
    
    }
}
